package Hot100.Skill_question;

public class sortColors {
    public static void main(String[] args) {
        int nums[] = {2,0,2,1,1,0};
        new sortColors().sortColors(nums);
    }
    public void sortColors(int[] nums) {
        int[] color = new int[3];
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] == 0){
                color[0]++;
            } else if (nums[i] == 1) {
                color[1]++;
            }else {
                color[2]++;
            }
        }
        int left = 0;
        for (int i = 0; i < 3; i++) {
            int right =left + 1;
            while(color[i] > 0){
                if(nums[left] == i){
                    left++;
                    right++;
                }else {
                    while (nums[right] != i){
                        right++;
                    }
                    int temp = nums[left];
                    nums[left] = nums[right];
                    nums[right] = temp;
                    left++;
                }
                color[i]--;
            }
        }

        for (int i = 0; i <nums.length; i++) {
            System.out.print(nums[i] + "  ");
        }

    }
}
